<?php

class NewsPage extends Page {
    static $has_many = array(
        'NewsItems' => 'NewsItem',
    );

    public function getCMSFields(){
        $f = parent::getCMSFields();
        $newsManager = new DataObjectManager(
            $this,
            'NewsItems',
            'NewsItem',
            array(
                'Title' => 'Titel',
                'Date' => 'Datum',
                'Archive' => 'Gearchiveerd'
            ),
            'getCMSFields_forPopup'
        );
        $f->addFieldToTab("Root.Content.NewsItems", $newsManager);
        return $f;
    }
}

class NewsPage_Controller extends Page_Controller {

    public function init(){
        parent::init();
        Requirements::themedCSS('News');
    }

    public function NewsItems(){
        return DataObject::get('NewsItem', 'NewsItem.NewsPageID = ' . $this->ID . ' AND NewsItem.Archive = 0');
    }
    
    function rss() {
        $rss = new RSSFeed($this->LatestUpdates(), $this->Link(), "4 happy feet nieuwsberichten", "Nieuwsberichten voor de leden van 4 happy feet, ook te vinden op de site.", "Title", "Message", "Author");
        $rss->outputToBrowser();
    }
 
    function LatestUpdates() {
        return DataObject::get('NewsItem', 'NewsItem.NewsPageID = ' . $this->ID . ' AND NewsItem.Archive = 0', 'Date DESC', '', '10');
    }
}